<?php
namespace app\house\controller;
use app\AdminRest;
use think\App;
use think\Request;
use app\house\model\AdminApartment as apartment_model;
use app\house\model\AdminHouse
    ;
class AdminApartment extends AdminRest
{

    protected $model;

    protected $houe_model;

    public function __construct(App $app) {
        parent::__construct($app);

        $this->model = new apartment_model();

        $this->houe_model = new AdminHouse();
    }
    /**
     * 房产价格户型
     */
    public function apartmentList(){
        $data = $this->model->apartmentList(['uniacid'=>$this->_uniacid]);
        return $this->success($data);
    }
    /**
     *
     * 添加房产户型
     */
    public function apartmentAdd(){
        $input = $this->_input;
        if(empty($input['title'])){
            return $this->error('名称不能为空');
        }
        $input['uniacid'] = $this->_uniacid;
        $res = $this->model->apartmentAdd($input);
        return $this->success($res);
    }
    /**
     *
     * 编辑房产户型
     */
    public function apartmentUpdate(){
        $input = $this->_input;
        if(count($input)>1){
            if(empty($input['title'])){
                return $this->error('名称不能为空');
            }
            $data = $this->model->apartmentUpdate(['id'=>$input['id']],$input);
        }else{
            $data = $this->model->apartmentInfo(['id'=>$input['id']]);
        }
        return $this->success($data);
    }
    /**
     *
     * 删除房产户型
     */

    public function apartmentDel(){

        $input = $this->_input;

        //查看该户型是否在被使用
        $dis = [
            'huxing_id' => $input['id']
        ];
        //查找正在被使用的房产
        $hx = $this->houe_model->houseInfo($dis);

        if(!empty($hx)){

            return $this->error('该户型正在被使用');
        }

        $res = $this->model->apartmentDel(['id'=>$input['id']]);

        return $this->success($res);
    }



}
